package com.zm.core.controller;

import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.zm.core.common.controller.BaseController;
import com.zm.core.model.Logo;

public class LogoController extends BaseController {

	public void index()
	{
		render("manage/logo.html");
	}
	public void getPage()
	{
		Page<Logo> page = Logo.dao.paginate(getParaToInt("page"), getParaToInt("rows"), "select * ", " from d_logo");
		setAttr("rows", page.getList());
		setAttr("total", page.getTotalRow());
		renderJson();
	}
	public void getById()
	{
		Logo logo = Logo.dao.findById(getPara("id"));
		renderJson(logo);
	}
	public void delete()
	{
		Logo.dao.deleteById(getPara("id"));
		this.setAttr("title", "提示");
		this.setAttr("message", "删除成功");
		renderJson();
	}
	public void submit()
	{
		Logo logo = getModel(Logo.class);
		if(logo.get("id")!=null)
		{
			Logo alreadylogo=Logo.dao.findFirst(" SELECT name FROM d_logo WHERE id = '"+logo.get("id").toString()+"' ");
			if(null!=alreadylogo)
			{
				logo.update();
				renderHtml("<script type='text/javascript'>alert('品牌保存成功')</script>");
				return;
			}
		}
		logo.save();
		renderHtml("<script type='text/javascript'>alert('品牌保存成功')</script>");

	}
	
	public void getList()
	{
		List<Logo> list = Logo.dao.find(" SELECT * FROM d_logo ");
		renderJson(list);
	}
	


}
